package edu.tamu.cse.teamproject1.Database;

/**
 * 
 * @author Ben Unsworth
 * 
 * This is a variable length string subclass for Tuple Element
 *
 *
 */

public class TupleVarCharElement extends TupleElement {
	
	/**
	 * constructor, defines the Tuple Element as a variable string
	 * of characters
	 * @param value
	 */
	public TupleVarCharElement(varchar value) {
		tupleValue = value;
		size = value.getSize();
		tupleType = EnumColumnType.varchar;
	}
	
	/**
	 * constructor, defines the tuple element as a variable string and sets
	 * it's size
	 * @param value, vcSize
	 */
	public TupleVarCharElement(varchar value, int vcSize){
		value.setString(value.getString(), vcSize);
		tupleType = EnumColumnType.varchar;
	}
	
	
	/**
	 * converts a string to variable size character array
	 * @param value
	 */
	public TupleVarCharElement(String value){
		varchar newVarChar = new varchar(value);
		tupleValue = newVarChar;
		size = value.length();
		tupleType = EnumColumnType.varchar;
	}
	
	/** 
	 * converts the string to a variable size character array
	 * and defines the size of the character array
	 * @param value, vcSize
	 */
	public TupleVarCharElement(String value, int vcSize){
		varchar newVarChar = new varchar(value, vcSize);
		tupleValue = newVarChar;
		size = vcSize;
		tupleType = EnumColumnType.varchar;
	}
	
	/**
	 * 
	 * @return the variable array of characters
	 */
	@Override
	public String getValue(){
		return (String)tupleValue.toString();
	}
	
	/**
	 * sets the tupleElement value as a variable array of characters
	 * @param value
	 */
	@Override
	public void setValue(Object value){
		varchar newValue = new varchar((String)value, size);
		tupleValue = newValue;
	}
	

	/**
	 * sets the size of the tupleElement
	 * @param newSize
	 */
	void setSize(int newSize){
		varchar newValue = (varchar)tupleValue;
		newValue.resize(newSize);
		tupleValue = newValue;
		size = newSize;
		
	}
}
